package training.bms.business;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

import javax.persistence.ManyToMany;
import javax.persistence.Table;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

import training.framework.business.AbstractEntity;

@Entity
@Table(name="TAG_TAG")
public class Tag extends AbstractEntity<Integer> {
	private Integer identifier;
	private String name;
	
	@Override
	public void setIdentifier(Integer identifier) {
		this.identifier = identifier;
	}
	
	
	@Override
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	@Column(name="TAG_IDENTIFIER")
	public Integer getIdentifier() {
		return this.identifier;
	}
	
	@NotNull
	@Size(min=1, max=100, message="Please specify the name of this tag (100 characters maximum)")
	@Column(name="TAG_NAME")
	public String getName() {
		return name;
	}
	
	public void setName(String name) {
		this.name = name;
	}
	
	// ------------------- RELATION ------------------- //
	
	private List<Post> posts =  new ArrayList<Post>();

	@ManyToMany(mappedBy="jpaTags")
	public List<Post> getPosts() {
		return posts;
	}

	public void setPosts(List<Post> posts) {
		this.posts = posts;
	}
}
